/*
	Copyright (c) 2007, ANYwebcam.com Pty Ltd. All rights reserved.

	The software in this package is published under the terms of the BSD style 
	license, a copy of which has been included with this distribution in the 
	license.txt file.
*/
package com.anywebcam.di.samples.movieApp
{
	public class MovieLister
	{
		public var movieSource:MovieSource;
		
		/*
		Alternatively to a public variable we could use either get/set accessors, or get/set-prefixed methods as demonstrated below.

		---

		The DI framework supports get & set accessors like these:

		public function get movieSource():MovieSource { return _movieSource; }
		public function set movieSource( value:MovieSource ):void { _movieSource = value; }

		---
		
		The DI framework also supports setter injection through set-prefixed methods like the below.
		The resolution to the method names is done automatically and does not need to be specified when 
		setting up the properties to inject.

		public function getMovieSource():MovieSource { return _movieSource; }
		public function setMovieSource( value:MovieSource ):void { _movieSource = value; }
		
		*/

		/**
		 * @param movieSource The MovieSource implementation to retrieve movies from
		 */
		public function MovieLister( movieSource:MovieSource )
		{
			this.movieSource = movieSource;
		}
		
		/**
		 * @param director The name of the director to search for movies by
		 * @return An Array of Movies
		 */
		public function getMoviesDirectedBy( director:String ):Array
		{
			var movies:Array = getAll();
			
			director = director.toLowerCase();
			
			if( movies ) return movies.filter( function( movie:Movie, index:int, array:Array ):Boolean
			{
				return ( movie.director.toLowerCase() == director );
			})
			
			return null;
		}
		
		
		/**
		 * @return All Movies from the MovieSource of this MovieLister
		 */
		public function getAll():Array
		{
			return movieSource.getAll();
		}
	}
}